public class LeetCode605 {

    public static void main(String[] args) {
        LeetCode605 leetCode605 = new LeetCode605();
        System.out.println(leetCode605.canPlaceFlowers(new int[]{0}, 1));
    }

    public boolean canPlaceFlowers(int[] flowerbed, int n) {

        int insertNum = 0;
        for (int i = 0; i < flowerbed.length; i++){
            if (i >= 1 && i < flowerbed.length - 1   && flowerbed[i] != 1){
                if (flowerbed[i - 1] == 0 && flowerbed[i + 1] == 0){
                    flowerbed[i] = 1;
                    insertNum++;
                }
            }

            if (i < 1  && flowerbed[i] != 1){
                if (flowerbed.length >= 2 && flowerbed[i + 1] == 0 ){
                    flowerbed[i] = 1;
                    insertNum++;
                }else if (flowerbed.length < 2 && flowerbed[i] == 0 ){
                    flowerbed[i] = 1;
                    insertNum++;
                }
            }

            if (i >= flowerbed.length - 1  && flowerbed[i] != 1){
                if (flowerbed[i - 1] == 0){
                    flowerbed[i] = 1;
                    insertNum++;
                }
            }
        }

        if (n <= insertNum){
            return true;
        }

        return  false;
    }
}
